import axios from 'axios';
import { ElMessage } from 'element-plus';
import qs from 'qs';

// let baseURL = '';
// if (process.env.VUE_APP_MODE === 'development') {
// 	baseURL = 'http://106.13.229.210:18765/';
// 	//开发环境下的执行操作
// } else if (process.env.VUE_APP_MODE === 'test') {
// 	//测试环境下的执行操作
// 	baseURL = 'http://106.13.229.210:18765/';
// } else {
// 	//生产环境下的执行操作
// 	baseURL = 'http://106.13.229.210:18765/';
// }

const service = axios.create({
  baseURL: '/', // 接口请求地址
  timeout: 1500000, // 请求超时时间
  headers: {
    'Content-Type': 'application/json ; charset=UTF-8',
  },
  withCredentials: true,
});

service.defaults.transformRequest = data => JSON.stringify(data);
service.interceptors.request.use(
  Config => {
    let token = localStorage.getItem('satoken');
    if (token != null) {
      token = token.replace(/\"/g, '');
    }
    token & (Config.headers.satoken = token);
    return Config;
  },
  error => {
    return Promise.reject(error);
  }
);

service.interceptors.response.use(response => {
  //  return response.data.data;
  const { code, data, msg } = response.data;
  if (code == 'success' || 200) {
    return data;
  } else if (code == 'error' || 'exception') {
    ElMessage.error(msg);
  } else if (code == 'warning') {
    ElMessage.warning(msg);
  } else {
    ElMessage.error('请求失败！！！');
  }
});

export default service;
